package com.yelobblog.yelobblog.mapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yelobblog.yelobblog.domain.Vo.commentsVo;
import com.yelobblog.yelobblog.domain.entity.comments;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;

@Mapper
public interface commentsMapper extends BaseMapper<comments> {

    @Update("UPDATE comments SET isDelete = #{isDelete} WHERE id = #{id}")
    void updateIsDelete(Integer id, Boolean isDelete);

    Page<commentsVo> getCommentsByArticleId(Page<?> page, Integer articleId);

    Page<commentsVo> getSubCommentsByRootCommentsId(Page<?> page, Integer rootCommentsId);

    @Update("update articles set commentCount=commentCount+1 where id = #{id}")
    void addCommentCount(Integer id);

    void deleteCommentCount(Integer id);

    @Update("update comment set likeCount=likeCount+1 where id = #{commentId}")
    void addLikeCount(Integer commentId);

    @Insert("INSERT INTO commentLike (userId, commentId) VALUES (#{userId}, #{commentId})")
    void addCommentLike(Integer userId, Integer commentId);

    @Update("update comment set likeCount=likeCount-1 where id = #{commentId}")
    void deleteLikeCount(Integer commentId);
    @Delete("DELETE FROM commentLike WHERE userId = #{userId} AND commentId = #{commentId}")
    void deleteCommentLike(Integer userId, Integer commentId);

    @Select("SELECT 1 FROM commentLike WHERE userId = #{userId} AND commentId = #{commentId} LIMIT 1")
    Integer getCommentLike(Integer userId, Integer commentId);
}
